﻿using System;
using System.Collections.Generic;
using System.IOC;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace HynuIOTA.Service
{
    public static class DBSessionFactory
    {
        /// <summary>
        /// 从线程中获取数据仓储
        /// </summary>
        /// <returns></returns>
        public static IRespository.IDBSession GetDBSession()
        {
            var dBSession = 
                CallContext.GetData(nameof(IRespository.IDBSession)) as IRespository.IDBSession;
            if (dBSession == null)
            {
                dBSession = IOContainer.GetInstance().Get<IRespository.IDBSession>();
                CallContext.SetData(nameof(IRespository.IDBSession), dBSession);
            }

            return dBSession;
        }
    }
}
